package com.inspur.edp.web.formmetadata.i18n.component.strategy.i18nresourcestrategy;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.inspur.edp.lcm.metadata.api.entity.I18nResourceItem;
import com.inspur.edp.lcm.metadata.api.entity.I18nResourceItemCollection;
import com.inspur.edp.web.common.utility.StringUtility;
import com.inspur.edp.web.formmetadata.i18n.I18nResourceItemManager;
import com.inspur.edp.web.formmetadata.i18n.component.ComponentUtility;
import com.inspur.edp.web.formmetadata.i18n.constant.I18nResourceConstant;

import java.util.ArrayList;
import java.util.HashMap;

public class StepsI18nResourceStrategy extends AbstractI18nResourceStrategy{
    @Override
    protected I18nResourceItemCollection extractAttributeI18nResourceItemCollection(String i18nResourceItemBaseId, HashMap<String, Object> currentComponent) {
        I18nResourceItemCollection i18nResourceItemCollection = new I18nResourceItemCollection();
        if (currentComponent.containsKey("stepData")) {
            String stepId = ComponentUtility.getInstance().getValue(currentComponent, "id");
            if (!StringUtility.isNullOrEmpty(stepId)) {
                ArrayList<HashMap<String, Object>> stepData = ComponentUtility.getInstance().getStepData(currentComponent);
                stepData.forEach(t -> {
                    String title = ComponentUtility.getInstance().getValue(t, "title");
                    String id = ComponentUtility.getInstance().getValue(t, "id");
                    if (!StringUtility.isNullOrEmpty(title) && !StringUtility.isNullOrEmpty(id)) {
                        String key = "ProgressStep" + I18nResourceConstant.SECOND_LEVEL_DELIMITER
                                + stepId + I18nResourceConstant.SECOND_LEVEL_DELIMITER
                                + "stepData" + I18nResourceConstant.SECOND_LEVEL_DELIMITER + id;
                        I18nResourceItem i18nResourceItem = I18nResourceItemManager.createI18nResourceItem(i18nResourceItemBaseId, key, title, title);
                        i18nResourceItemCollection.add(i18nResourceItem);
                    }
                });
            }

        }
        return i18nResourceItemCollection;
    }
}
 